<?php
/**
 * Class Cert
 */

namespace App\Models;

use App\Models\base\CertBase;

/**
 * App\Models\Cert
 *
 * @property int $cert_id
 * @property string $cert_no
 * @property string|null $updated_at
 * @property string|null $created_at
 * @property string|null $deleted_at
 * @property string|null $pet_name 宠物名字
 * @property string|null $province 省
 * @property string|null $birthday 生日
 * @property string|null $sex 性别
 * @property string|null $big_cat 类别
 * @property string|null $cert_images
 * @property string|null $cert_people_info 宠物主人信息
 * @property string|null $vaccine_info
 * @property string|null $Insect_info
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereBigCat($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereBirthday($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereCertId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereCertImages($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereCertNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereCertPeopleInfo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereInsectInfo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert wherePetName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereProvince($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereSex($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Cert whereVaccineInfo($value)
 * @mixin \Eloquent
 */
class Cert extends CertBase
{
    protected $casts = [
        'insect_info' => 'json',
    ];
    public function setCertImagesAttribute($value)
    {
        if(!empty($value)){
            $this->attributes['cert_images'] = json_encode($value);
        }
    }

    /**
     * 图片
     * @param $value
     * @return mixed
     */
    public function getCertImagesAttribute($value){
        if(!empty($value)){
            return json_decode($value);
        }
    }

    public function getVaccineInfoAttribute($extra)
    {
        return array_values(json_decode($extra, true) ?: []);
    }

    public function setVaccineInfoAttribute($extra)
    {
        $this->attributes['vaccine_info'] = json_encode(array_values($extra));
    }


    /**
     * 关系
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function cert_province(){
        return $this->hasOne(CertProvince::class,'cert_province_id','province');
    }

    public function vaccine(){
        return $this->hasMany(Vaccine::class,'cert_id');
    }





}
